#!/bin/bash

# 1. 检查程序的运行状态，避免重复启动
## 1.1 ps -ef | grep "yhs_start.sh" 得到含用 yhs_start.sh 命令的进程，
## 1.2 grep -v grep 排除当前脚本命令的进程
## 1.3 awk '{print $2}'  得到  APScheduler 进程的进程ID
kill_pid=`ps -ef | grep "yhs_start.sh"  |grep -v grep | awk '{print $2}'`

# 判断进程是否存在，如果存在，则不在再重复执行
if [ -n "${kill_pid}" ]
then
	echo "pid = "${kill_pid}
    echo "yhs_start.sh 程序正在运行中，请勿重复启动"
    exit 1
else
    YHS_MIDWARE="/home/yhs/.wrks/hkprinter/HKPrinter"
    YHS_MIDWARE_LIB=${YHS_MIDWARE}/devel/lib
    YHS_MIDWARE_BIN=${YHS_MIDWARE}/devel/lib/ros_midware
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$YHS_MIDWARE_LIB
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$YHS_MIDWARE_BIN
    source ${YHS_MIDWARE}/devel/setup.bash --extend
    ${YHS_MIDWARE_BIN}/run_robot ${YHS_MIDWARE}/config/config.yaml
    echo "yhs_start.sh 启动"
fi

# # 2. nohup  后台运行脚本
# nohup python3 ./APScheduler.py >nohup.out   2>&1 &

# # 3. 显示日志
# tail -200f ./nohup.out